package com.hula.onion.book.server.spider.platforms.jimuhezi;

import com.hula.onion.book.server.common.LoginForm;
import com.hula.onion.book.server.model.AccountInfo;
import com.hula.onion.book.server.utils.MD5Utils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * Description:
 * Create Date:2018/1/17 19:49
 *
 * @author shan
 * @version 1.0
 */
@Component
public class JiMuHeZiSpiderHelper {

    /**
     * 组装请求参数
     *
     * @param form
     * @return
     */
    public Map<String, Object> installRequestParams(LoginForm form) throws Exception {

        Map<String, Object> map = new HashMap<>(4);

        map.put("username", form.getUserName());
        map.put("password", form.getPassword());
        map.put("site", "");
        map.put("agreeContract", "on");

        return map;

    }

    /**
     * 解析账户余额
     *
     * @param html
     * @return
     */
    public AccountInfo parseAccountBalance(String html) {

        AccountInfo accountInfo = new AccountInfo();

        Document dc = Jsoup.parse(html);

        //总资产
        String amount = dc.selectFirst("li.sum-item.frist").childNode(3).childNode(1).childNode(0).outerHtml();

        String totalIntrest = dc.getElementById("incomeDetail").child(0).text();

        accountInfo.setAmount(new BigDecimal(amount));
        accountInfo.setTotalIntrest(new BigDecimal(totalIntrest));

        return accountInfo;
    }


}
